{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
        <div id="js_main_header" class="ui-form main_header">
        <span>
            <select name="status" id="status" class="form-control" style="width:120px">
                <option value="">筛选用户状态</option>
                <option value="0">待审核</option>
                <option value="1">通过</option>
                <option value="2">拒绝</option>
            </select>
        </span>
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名称" value="" class="frm_input"/>
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'username',width:200,align:'center'">用户名</th>    
        <th data-options="field:'name',width:200,align:'center'">区域名称</th>    
        <th data-options="field:'agent_level',width:200,align:'center',formatter:formatDefault">区域类型</th>    
        <th data-options="field:'status',width:200,align:'center',formatter:formatStatus">类型</th>    
        <th data-options="field:'create_time',width:200,align:'center'">申请时间</th>    
        <th data-options="field:'update_time',width:200,align:'center'">编辑时间</th>    
        </thead>
        <thead>
            <tr>
                <th data-options="field:'_oper',width:150,halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>

{/block}
{block name="script"}
<script type="text/javascript">
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        if(row['status']==0) {
            html += '<button type="button" onclick="pass(' + row['id'] + ',1)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-cloud"></i>通过</button>';
            html += '<button type="button" onclick="pass(' + row['id'] + ',2)" class="btn btn-xs btn-default edit-btn"><i class="icon wb-warning"></i>拒绝</button>';
        }
        // if(row['is_default'] != '1')
            // html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default del-btn"><i class="icon wb-close"></i>删除</button>';
        // html += '</span>';
        return html;
    }
    

    function formatDefault(value, row,index){
        if(value == '1')
            text = '县级';
        if(value == '2')
            text = '市级';
        if(value == '3')
            text = '省级';
        return text;
    }

    function formatStatus(value, row,index){
        if(value == '1')
            text = '通过';
        if(value == '2')
            text = '拒绝';
        if(value == '0')
            text = '待审核';
        return text;
    }


    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });

    function pass(id,status) {
        confirm("确认审核?", function () {
            var url = getURL('examine');
            $.getJSON(url, {id: id,status:status}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 650, 450, url, function () {
            reload();
        }, ['保存', '取消']);
    }

    $("#js_search").click(function () {
        reload();
    });
    function reload() {
        var keyword = $("#js_keyword").val();
        var status = $("#status").val();
        $('#grid-table').datagrid('reload', {keyword: keyword,status:status});
    }
    $("#status").change(function () {
        reload();
    });
</script>
{/block}